import request from '@/utils/request'
import type { ApiResponse } from '@/utils/request'

// 康复计划接口定义
export interface RehabilitationPlanData {
  id?: number
  patientId: number
  therapistId: number
  title: string
  description: string
  injuryReportId?: number
  startDate: string
  endDate: string
  status: number

  // 训练项目1
  item1Name?: string
  item1Description?: string
  item1Frequency?: string
  item1Sets?: number
  item1Repetitions?: number
  item1Duration?: number
  item1Notes?: string

  // 训练项目2
  item2Name?: string
  item2Description?: string
  item2Frequency?: string
  item2Sets?: number
  item2Repetitions?: number
  item2Duration?: number
  item2Notes?: string

  // 训练项目3
  item3Name?: string
  item3Description?: string
  item3Frequency?: string
  item3Sets?: number
  item3Repetitions?: number
  item3Duration?: number
  item3Notes?: string

  // 训练项目4
  item4Name?: string
  item4Description?: string
  item4Frequency?: string
  item4Sets?: number
  item4Repetitions?: number
  item4Duration?: number
  item4Notes?: string

  // 训练项目5
  item5Name?: string
  item5Description?: string
  item5Frequency?: string
  item5Sets?: number
  item5Repetitions?: number
  item5Duration?: number
  item5Notes?: string

  // 进度记录
  progressStatus?: number
  progressNotes?: string
  studentFeedback?: string
  lastReviewDate?: string
}

// 进度更新接口
export interface ProgressUpdateData {
  id: number
  progressStatus: number
  progressNotes: string
  studentFeedback: string
}

// 查询参数接口
export interface QueryParams {
  page?: number
  pageSize?: number
  keyword?: string
  status?: number | string
  patientId?: number
}

/**
 * 添加康复计划
 * @param data 康复计划数据
 */
export function addRehabilitationPlan(data: RehabilitationPlanData): Promise<ApiResponse<number>> {
  return request({
    url: '/rehabilitation/add',
    method: 'post',
    data,
  })
}

/**
 * 更新康复计划
 * @param data 康复计划更新数据
 */
export function updateRehabilitationPlan(
  data: RehabilitationPlanData,
): Promise<ApiResponse<number>> {
  return request({
    url: '/rehabilitation/update',
    method: 'post',
    data,
  })
}

/**
 * 更新康复计划进度
 * @param data 进度更新数据
 */
export function updateRehabilitationProgress(data: ProgressUpdateData) {
  return request({
    url: '/rehabilitation/progress/update',
    method: 'post',
    data,
  })
}

/**
 * 获取康复计划详情
 * @param id 康复计划ID
 */
export function getRehabilitationPlan(
  id: number | string,
): Promise<ApiResponse<RehabilitationPlanData>> {
  return request({
    url: '/rehabilitation/get',
    method: 'get',
    params: { id },
  })
}

/**
 * 获取理疗师创建的康复计划列表
 * @param params 查询参数
 */
export function getTherapistRehabilitationList(params: QueryParams) {
  return request({
    url: '/rehabilitation/list/therapist',
    method: 'get',
    params,
  })
}

/**
 * 获取患者的康复计划列表
 * @param params 查询参数
 */
export function getPatientRehabilitationList(params: QueryParams) {
  return request({
    url: '/rehabilitation/list/patient',
    method: 'get',
    params,
  })
}

/**
 * 获取与伤病报告关联的康复计划
 * @param injuryReportId 伤病报告ID
 */
export function getInjuryRehabilitationList(
  injuryReportId: number | string,
): Promise<ApiResponse<RehabilitationPlanData[]>> {
  return request({
    url: '/rehabilitation/list/injury',
    method: 'get',
    params: { injuryReportId },
  })
}
